﻿using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BizBrowser.RPT.PrintEntity
{
    public class JsonUtil
    {
        public static List<RptHeaderFooter> parseHeaderFooter(String json)
        {
            if (json != null)
            {
                try
                {
                    IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                    timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                    List<RptHeaderFooter> data = JsonConvert.DeserializeObject<List<RptHeaderFooter>>(json,timeFormat);
                    return data;
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex);
                    return null;
                }
            }
            return null;
        }

        public static List<RptDetail> parseDetail(String json)
        {
            if (json != null)
            {
                try
                {
                    IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                    timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                    List<RptDetail> data = JsonConvert.DeserializeObject<List<RptDetail>>(json,timeFormat);
                    return data;
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex);
                    return null;
                }
            }
            return null;
        }


    }
}
